import pytest
from api.login import LoginAPI
from common.jsonutil import build_data
from api.dept import DeptAPI
import config
from common.assertutil import common_assert


# 测试用例
class TestLoginAPI:
    token666 = None

    # 前置条件
    def setup_class(self):
        self.login_api = LoginAPI()
        self.dept_api = DeptAPI()

        # 登录成功
        response = self.login_api.login(login_data={"mobile": "13800000002", "password": "123456"})
        # 提取data并保存
        TestLoginAPI.token666=response.json().get("data")
        print(TestLoginAPI.token666)

    # 添加部门
    @pytest.mark.parametrize("dept_data, status_code, success, code, message", build_data(f'{config.BASE_PATH}/data/add.json'))
    def test_add_dept(self, dept_data, status_code, success, code, message):
        response = self.dept_api.add_dept(TestLoginAPI.token666, dept_data)
        print(response.json())
        # 断言
        common_assert(response,status_code, success, code, message)
